// pages/ucenter/changeInfo/changeInfo.js
var app = getApp();
var hostURL = app.globalData1.hostURL;
Page({

 
  data: {
  id:'',
  publish:{},
  },

  
  onLoad: function (options) {
   
     this.setData({
      id: options.index, 
    }) 
    this.setData({
      publish: wx.getStorageSync("mypublish")[this.data.id],
    
    })
   
    console.log(",,"+this.data.id)
    console.log(wx.getStorageSync("mypublish")[this.data.id].source_name)
    
  },

    formSubmit: function (e) {

     var info = e.detail.value;

       console.log(info);
      
       this.modify(info)
    
  },
  
  
    modify:function(info){
      let that = this;
      // that.data.publish.source_name = info.gooodsname;
      that.data.publish.source_count = info.number;
      that.data.publish.source_price = info.price;
      that.data.publish.source_deposit = info.deprice;
      that.data.publish.source_text=info.txt;
      console.log(".."+that.data.publish.source_count)
      console.log(wx.getStorageSync("mypublish")[this.data.id].sourceId)
      //  wx.getStorageSync("publish")[this.data.id].source_name
      // console.log(wx.getStorageSync("publish")[this.data.id].source_name)
     wx.request({

    url: hostURL+'sharedplatform-web/publish/alterPublish.action',
    data: {

      source_id: wx.getStorageSync("mypublish")[this.data.id].sourceId,
      source_name: info.goodsname,
      source_count: info.number,
      source_price: info.price,
      source_deposit: info.deprice,
      source_text: info.txt,

     },
     method: 'get',
     header: {
       'content-type': 'application/x-www-form-urlencoded'
     },
     success: function (res) 
    {
       var mypublish
       if (res.data.errno == 1) {
         
         wx.showToast({
           title: '修改发布信息失败！',
         })
       }
       else{
         that.setData({
           mypublish: res.data.alterSourceDetail,
         })
       
         wx.setStorageSync('publish', res.data.alterSourceDetail);
        
         console.log(res.data.alterSourceDetail)
         wx.showToast({
           title: '修改发布信息成功！',

         })
         wx.switchTab({
           url: '../index/index',
           success: function (e) {
             var page = getCurrentPages().pop();
             if (page == undefined || page == null) return;
             page.onLoad()
           }
         });
         
       }
   
    }
   
   
   })
  
  }


})